-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to locally prevent event propagation #9749
Conversation
Would be nice to get some 👀 on this I presume @roryabraham. Should we look for an internal or external engineer to help? |
This was just a POC stemming from this slack thread. I never really intended to have this merged or take on the issue myself. Was just trying to help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.removeEventListener('keydown', bindHandlerToKeydownEvent); | ||
window.addEventListener('keydown', bindHandlerToKeydownEvent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this code is not required. Could you explain why did you add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall right now, but found that it was necessary in my testing, which was pretty thorough for the login page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea is that we establish these event handlers in the bubbling phase so that further down in the DOM we can prevent them from being triggered in the capture phase.
If you have a capture-phase handler at the document root, then there's no way to prevent it from executing first
onKeyDownCapture={(e) => { | ||
e.stopPropagation(); | ||
Session.clearSignInData(); | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so but I don't have ideas on this. Rory will have better ideas on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think you would have to add this code to every such component OR create a wrapper component like FormPressable
that has it built-in and use it for all pressables within forms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do the reverse? Create a form wrapper component and add onKeyDownCapture
and check if the target is INPUT, TEXTAREA, SELECT
and trigger the submit function. I believe this will fix the issue without any sideeffects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roryabraham Are these changes you are expecting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that POC looks good to me 👍
Details
React 17 changed where events handlers are set up from
document
to the root node (see changes to EventDelegation).Before, we solved this by making global event handlers attached to the
document
use the capturing phase, so they always execute first. However, this makes it impossible for a local event handler to execute before the global one and prevent propagation to the parent handler, because thedocument
in capturing phase will always be the first to receive any event. This PR changes that, so that we just set up event listeners in the bubbling phase (as is a more common practice). We now attach global event handlers to the same place React will (i.e:rootNode
) instead of to the parentdocument
.Fixed Issues
$ (related to) #7918
Tests
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Screenshots
Web
Mobile Web
Desktop
iOS
Android